Imports System.Data.SqlClient

Public Class User
    Private sUsername As String
    Private sFullname As String
    Private sPassword As String
    Private sType As String

    Public Property Username() As String
        Get
            Return sUsername
        End Get
        Set(ByVal Value As String)
            sUsername = Value
        End Set
    End Property
    Public Property Fullname() As String
        Get
            Return sFullname
        End Get
        Set(ByVal Value As String)
            sFullname = Value
        End Set
    End Property
    Public Property Password() As String
        Get
            Return sPassword
        End Get
        Set(ByVal Value As String)
            sPassword = Value
        End Set
    End Property
    Public Property UserType() As String
        Get
            Return sType
        End Get
        Set(ByVal Value As String)
            sType = Value
        End Set
    End Property
End Class

Public Class UserF

    Public Function ExistsAccount(ByVal Username As String, ByVal Password As String) As Boolean
        Dim myProjectCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        myCnn = myProjectCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "_User_ExistsAccount"
            .Parameters.Add(New SqlClient.SqlParameter("@Username", SqlDbType.VarChar))
            .Parameters("@Username").Value = Username
            .Parameters.Add(New SqlClient.SqlParameter("@Password", SqlDbType.VarChar))
            .Parameters("@Password").Value = Password

            .Parameters.Add(New SqlClient.SqlParameter("@Return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With
        If myCmd.Parameters("@Return").Value = 1 Then
            myCnn.Close()
            Return True
        Else
            myCnn.Close()
            Return False
        End If

    End Function

    Public Function GetWhereUserName(ByVal UserName As String) As DataTable
        Dim myProjectCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjectCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "_User_GetWhereUsername"

            .Parameters.Add(New SqlClient.SqlParameter("@Username", SqlDbType.VarChar))
            .Parameters("@Username").Value = Username
        End With

        myDat = New SqlDataAdapter(myCmd)
        myDat.Fill(myDtb)
        Return myDtb
        myCnn.Close()
    End Function

    Public Function ChangePassword(ByVal Username As String, ByVal Password As String) As Boolean
        Dim myProjectCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        myCnn = myProjectCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlClient.SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "_User_ChangePassword"

            .Parameters.Add(New SqlClient.SqlParameter("@Username", SqlDbType.VarChar))
            .Parameters("@Username").Value = Username

            .Parameters.Add(New SqlClient.SqlParameter("@Password", SqlDbType.VarChar))
            .Parameters("@Password").Value = Password

            .Parameters.Add(New SqlClient.SqlParameter("@Return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With
        If myCmd.Parameters("@Return").Value = 1 Then
            myCnn.Close()
            Return True
        Else
            myCnn.Close()
            Return False
        End If
    End Function

End Class